﻿<!DOCTYPE HTML>
<html>
<head>
    {include file="common:meta"}
    <link type="text/css" rel="stylesheet" href="/static/admin/plugin/bootstrap-fileinput/css/fileinput.css"/>
</head>
<body>
<div class="page-container">
    <div class=" float-e-margins">
        <div class="ibox-content">
            <div class="tabs-container">
                <ul class="nav nav-tabs">
                    <li class="active"><a data-toggle="tab" href="#tab-1" aria-expanded="true">版本列表</a>
                    </li>
                    <li class=""><a data-toggle="tab" href="#tab-2" aria-expanded="false">版本添加</a>
                    </li>
                </ul>
                <div class="tab-content">
                    <div class=" tab-pane active" id="tab-1">
                        <table id="tb_departments"></table>
                    </div>
                    <div class=" tab-pane" id="tab-2">
                        <div class="ibox-content">
                            <form class="form-horizontal" id="form" data-url="/AppManageAdd">
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="type">
                                        <span class="c-red">*</span>渠道：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <select class="form-control" name="gift_id" id="type">
                                            <option value="1">安卓</option>
                                            <option value="2">IOS</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="code">
                                        <span class="c-red">*</span>内部版本号：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <input type="number" class="form-control" id="code" value="0" name="egg_price">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="md5_value">
                                        <span class="c-red">*</span>md5：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <input type="text" class="form-control" id="md5_value" name="md5_value">
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="update_value">
                                        <span class="c-red">*</span>更新说明：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <textarea class="form-control" id="update_value" name="update_value"></textarea>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="type">
                                        <span class="c-red">*</span>是否强制更新：
                                    </label>
                                    <div class="col-md-2 col-sm-10">
                                        <select class="form-control" name="gift_id" id="type">
                                            <option value="1">是</option>
                                            <option value="2">否</option>
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group">
                                    <label class="col-sm-2 control-label" for="file">
                                        选择文件
                                    </label>
                                    <div class="col-md-6 col-sm-10">
                                        <input id="file" name="file" type="file" multiple class="file-loading">
                                    </div>
                                </div>
                                <input id="img_address" name="down_url" type="hidden">
                                <div class="form-group">
                                    <div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
                                        <button class="btn btn-primary" type="button" onclick="commonSubmit(this)">添加
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="common:footer"}
<script type="text/javascript" src="/static/admin/plugin/bootstrap-fileinput/js/fileinput.js"></script>

<script type="text/javascript" src="/static/admin/plugin/bootstrap-fileinput/js/locales/zh.js"></script>
<script>
    $(document).on('ready', function () {
        $("#file").fileinput({
            language: 'zh', //设置语言

            uploadUrl: "/AppManageGetApp", //上传的地址

            allowedFileExtensions: ['apk', 'jpg', 'png'],//接收的文件后缀

            uploadAsync: false, //默认异步上传

            showUpload: true, //是否显示上传按钮

            showRemove: true, //显示移除按钮

            showPreview: true, //是否显示预览

            browseClass: "btn btn-primary", //按钮样式

            maxFileCount: 1, //表示允许同时上传的最大文件个数

            enctype: 'multipart/form-data',

            validateInitialCount: true,

            previewFileIcon: "<iclass =" + 'glyphicon glyphicon-king' + "></i>",

            msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！"
        }).on("filebatchuploadsuccess", function (event, data) {
            if (data) {
                $("#img_address").val(data.response);
                console.log(data.response);
            }
        });
    });


    $(document).ready(function () {
        initTable();
    });

    function initTable() {
        $('#tb_departments').bootstrapTable({
            url: '/AppManageIndexData',         //请求后台的URL（*）
            dataField: "data",
            method: 'post',                      //请求方式（*）
            striped: true,                      //是否显示行间隔色
            cache: true,                       //是否使用缓存，默认为true，所以一般情况下需要设置一下这个属性（*）
            pagination: true,                   //是否显示分页（*）
            queryParams: queryParams,//传递参数（*）
            showToggle: true,
            showRefresh: true,
            sidePagination: "server",           //分页方式：client客户端分页，server服务端分页（*）
            pageNumber: 1,                       //初始化加载第一页，默认第一页
            pageSize: 10,                       //每页的记录行数（*）
            pageList: [10, 25, 50, 100],        //可供选择的每页的行数（*）
            showColumns: true,                  //是否显示所有的列
            showPaginationSwitch: true,
            minimumCountColumns: 2,             //最少允许的列数

            columns: [{
                field: 'id',
                title: 'ID'
            }, {
                field: 'type',
                title: '安卓/苹果',
                formatter: function (value, row, index) {
                    return row.type === 1 ? '安卓' : 'IOS';
                }
            }, {
                field: 'version',
                title: '版本号',
            }, {
                field: 'code',
                title: '内部版本号',
                visible: false
            }, {
                field: 'update_value',
                title: '更新描述',
            }, {
                field: 'md5_value',
                title: 'MD5',
                visible: false
            }, {
                field: 'download_url',
                title: '下载地址',
                visible: false
            }, {
                field: 'update_time',
                title: '更新时间',
                formatter: function (value, row, index) {
                    return getLocalTime(row.update_time);
                }
            }, {
                field: 'Button',
                title: '操作',
                events: operateEvents,
                formatter: operateFormatter
            }],
        });
    }

    //得到查询的参数

    function queryParams(params) {
        params.offset = params.offset / params.limit + 1;
        console.log(JSON.stringify(params));
        return params;
    }

    function operateFormatter(value, row, index) {


        if(row.status === 1)
            var is_force_format = '强制';
        else
            var is_force_format = '不强制';

        if(row.is_open === 1)
            var is_open_format = '下架';
        else
            var is_open_format = '上架';

        return [
            '<button type="button"  class="TableChangeForce btn btn-primary btn-sm" style="margin-right:15px;">' + is_force_format + '</button>',
            '<button type="button"  class="TableChangeOpen btn btn-primary btn-sm" style="margin-right:15px;">' + is_open_format + '</button>',
        ].join('');
    }

    window.operateEvents = {
        'click .TableChangeOpen': function (e, value, row, index) {

            changeForceStatus('AppManageEdit', row, this,1);
        },
        'click .TableChangeForce': function (e, value, row, index) {
            changeForceStatus('AppManageEdit', row, this,2);
        }
    };

    function changeForceStatus(url, row, obj,flag) {
        var prize_status = '';
        if(flag === 1){
            prize_status = row.is_open === 1 ? '上架' : '下架';
            row.is_open === 1 ? row.is_open = 0 : row.is_open = 1;

        }
        if(flag === 2){
            prize_status = row.status === 1 ? '不强制' : '强制';
            row.status === 1 ? row.status = 2 : row.status = 1;
        }

        $.ajax({
            type: 'get',
            dataType: 'json',
            url: url,
            data: row,
            success: function (re) {
                if (re.code === 100) {
                    layer.msg(re.msg, {icon: 1, time: 2000});
                    $(obj).html(prize_status);
                } else {
                    layer.alert(re.msg);
                }
            },
            error: function (data) {
                console.log(data.msg);
            }
        });
    }
    // 搜索按钮触发事件
    $(function () {
        $("#eventQuery").click(function () {
            $('#tb_departments').bootstrapTable(('refresh'));	// 很重要的一步，刷新url！
        });

    });
</script>
</body>
</html>